<template>
	<ui-action-sheet 
		class="bi-sort-select"
		ref="actionSheet"
	>
		<view class="bi-sort-select__handle" slot="handle">
			<view class="bi-sort-select__handle-inner">
				<view class="bi-sort-select__handle-icon">
					<ui-icon name="filter-2-line"></ui-icon>
				</view>
				<view class="bi-sort-select__handle-text">
					排序
				</view>
			</view>
		</view>
		<template v-if="items && items.length">
			<ui-action-sheet-item
				v-for="(item, index) in items"
				:key="index"
				:type="value && value.order === item.order && value.prop === item.prop ? 'primary' : 'default'"
				@click="handleItemClick(item)"
			>{{ item.text }}</ui-action-sheet-item>
		</template>
	</ui-action-sheet>
</template>

<script>
	export default {
		name: 'BiSortSelect',
		props: {
			/**
			 * {
			 *    prop: 'xxx',
			 * 	  order: 'asc'
			 * } 
			 */
			value: {
				type: Object
			},
			/**
			 * [{
		     * 		text: '',
			 * 		prop: '',
			 * 		order: ''
			 * }]
			 */
			items: {
				type: Array
			}
		},
		methods: {
			handleItemClick (item) {
				this.$emit('input', {
					prop: item.prop,
					order: item.order
				})
				this.$refs.actionSheet.close()
			}
		}
	}
</script>

<style lang="less">
.bi-sort-select__handle{
	min-width: 36px;
	height: 36px;
	line-height: 36px;
	padding: 0 3px;
	border-radius: 3px;
	display: inline-block;
	border-radius: 3px;
	&:active {
		opacity: .7;
	}
}
.bi-sort-select__handle-inner{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}
.bi-sort-select__handle-icon{
	width: 18px;
	height: 18px;
	line-height: 18px;
	text-align: center;
}
.bi-sort-select__handle-text {
	height: 18px;
	line-height: 18px;
	font-size: 12px;
}
</style>